package com.hospital.vac.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hospital.vac.entity.Role;
import com.hospital.vac.entity.UserRole;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @description 角色数据访问层
 * @return
 * @author ANLGIN
 * @since 2023/3/9 17:09
 */

public interface RoleMapper extends BaseMapper<Role> {

    /**
    * 根据id查询用户角色
    */
    @Select("select * from user_role where user_id = #{userId}")
    List<UserRole> getUserRoleByUserId(Integer userId);

    /**
     * 根据id删除用户角色
     */
    @Delete("delete from user_role where user_id = #{userId}")
    void deleteRoleByUserId(Integer userId);

    /**
     * 插入用户角色
     */
    @Insert("insert into user_role(user_id, role_id) values(#{userId}, #{roleId})")
    void insertUserRole(Integer userId, Integer roleId);
}
